function fenToArray(fen) {
	let row = fen.split(' ')[0].split("/");
	let arr = [
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 0, 0, 0, 0, 0, 0, 0],
		[0, 0, 0, 0, 0, 0, 0, 0, 0]
	];
	for (let i = 0; i < row.length; i++) {
		let col = row[i].split('');
		let k = 0;
		for (let j = 0; j < col.length; j++) {
			if (col[j] >= '1' && col[j] <= '9') {
				k += parseInt(col[j]);
			} else {
				arr[i][k] = col[j];
				k++;
			}
		}
	}
	return arr;
}

function arrToPieces(arr) {
	let pieces = [];
	let red = "DarkRed";
	let black = "Black";
	for (let i = 0; i < arr.length; i++) {
		for (let j = 0; j < arr[i].length; j++) {
			switch (arr[i][j]) {
				case 'R':
					pieces.push({
						x: i,
						y: j,
						color: red,
						name: "俥"
					});
					break;
				case 'r':
					pieces.push({
						x: i,
						y: j,
						color: black,
						name: "車"
					});
					break;
				case 'N':
					pieces.push({
						x: i,
						y: j,
						color: red,
						name: "傌"
					});
					break;
				case 'n':
					pieces.push({
						x: i,
						y: j,
						color: black,
						name: "馬"
					});
					break;
				case 'B':
					pieces.push({
						x: i,
						y: j,
						color: red,
						name: "相"
					});
					break;
				case 'b':
					pieces.push({
						x: i,
						y: j,
						color: black,
						name: "象"
					});
					break;
				case 'A':
					pieces.push({
						x: i,
						y: j,
						color: red,
						name: "仕"
					});
					break;
				case 'a':
					pieces.push({
						x: i,
						y: j,
						color: black,
						name: "士"
					});
					break;
				case 'K':
					pieces.push({
						x: i,
						y: j,
						color: red,
						name: "帥"
					});
					break;
				case 'k':
					pieces.push({
						x: i,
						y: j,
						color: black,
						name: "將"
					});
					break;
				case 'C':
					pieces.push({
						x: i,
						y: j,
						color: red,
						name: "炮"
					});
					break;
				case 'c':
					pieces.push({
						x: i,
						y: j,
						color: black,
						name: "砲"
					});
					break;
				case 'P':
					pieces.push({
						x: i,
						y: j,
						color: red,
						name: "兵"
					});
					break;
				case 'p':
					pieces.push({
						x: i,
						y: j,
						color: black,
						name: "卒"
					});
					break;
			}
		}
	}
	return pieces;
}
